package com.example.zhu.service.Impl;

import com.example.zhu.mapper.LessonMapper;
import com.example.zhu.result.Result;
import com.example.zhu.service.LessonService;
import com.example.zhu.vo.LessonVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;

@Service
public class LessonServiceImpl implements LessonService {

    @Autowired
    private LessonMapper lessonMapper;

    /**
     * 查询所有刷课订单
     */
    public List<LessonVO> selectAll() {
        List<LessonVO> list = lessonMapper.selectAll();
        return list;
    }

    /**
     * 条件查询
     * @param productId
     * @param start
     * @param end
     * @return
     */
    public List<LessonVO> getByCondition(String productId, String start, String end) {
        if(!"null".equals(start)){
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            start = format.format(Long.parseLong(start));
        }
        if(!"null".equals(end)){
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            end = format.format(Long.parseLong(end));
        }
        List<LessonVO> list = lessonMapper.getByCondition(productId,start,end);
        return list;
    }

    /**
     * 删除订单
     * @param id
     * @return
     */
    public Result deleteById(Integer id) {
        lessonMapper.deleteById(id);
        return Result.success();
    }
}
